package com.ruoyi.web.controller.module.platform;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.platform.PlatformPay;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.module.platform.IPlatformPayService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 银行支付列Controller
 *
 * @author ruoyi
 * @date 2022-09-13
 */
@Validated
@Api(value = "银行支付列控制器", tags = {"银行支付列管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/pay")
public class PlatformPayController extends BaseController {

    private final IPlatformPayService platformPayService;

    /**
     * 查询银行支付列列表
     */
    @ApiOperation("查询银行支付列列表")
//    @PreAuthorize("@ss.hasPermi('module:pay:list')")
    @GetMapping("/list")
    public TableDataInfo<PlatformPay> list(@Validated PlatformPay platformPay) {
        QueryWrapper<PlatformPay> qw = new QueryWrapper<>();
        if(platformPay.getQuery()!=null){
            qw.like("mer_no",platformPay.getQuery())
                    .or().like("terminal_no",platformPay.getQuery())
                    .or().like("mer_name",platformPay.getQuery());
        }
        if(platformPay.getId()!=null){
            qw.eq("id",platformPay.getId());
        }
        TableDataInfo<PlatformPay> td = PageUtils.buildDataInfo(platformPayService.page(PageUtils.buildPage(),qw));
        List<PlatformPay> list = td.getRows();
        return td;
    }

    /**
     * 导出银行支付列列表
     */
    @ApiOperation("导出银行支付列列表")
    @PreAuthorize("@ss.hasPermi('module:pay:export')")
    @Log(title = "银行支付列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<PlatformPay> export(@Validated PlatformPay platformPay) {
        List<PlatformPay> list = platformPayService.list();
        ExcelUtil<PlatformPay> util = new ExcelUtil<PlatformPay>(PlatformPay.class);
        return util.exportExcel(list, "银行支付列");
    }

    /**
     * 获取银行支付列详细信息
     */
    @ApiOperation("获取银行支付列详细信息")
    @PreAuthorize("@ss.hasPermi('module:pay:query')")
    @GetMapping("/{id}")
    public AjaxResult<PlatformPay> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        PlatformPay platformPay = platformPayService.getById(id);
        return AjaxResult.success(platformPay);
    }

    /**
     * 新增银行支付列
     */
    @ApiOperation("新增银行支付列")
    @PreAuthorize("@ss.hasPermi('module:pay:add')")
    @Log(title = "银行支付列", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody PlatformPay platformPay) {
        return toAjax(platformPayService.save(platformPay) ? 1 : 0);
    }

    /**
     * 修改银行支付列
     */
    @ApiOperation("修改银行支付列")
    @PreAuthorize("@ss.hasPermi('module:pay:edit')")
    @Log(title = "银行支付列", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody PlatformPay platformPay) {
        return toAjax(platformPayService.updateById(platformPay) ? 1 : 0);
    }

    /**
     * 删除银行支付列
     */
    @ApiOperation("删除银行支付列")
    @PreAuthorize("@ss.hasPermi('module:pay:remove')")
    @Log(title = "银行支付列" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Long[] ids) {
        return toAjax(platformPayService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
